package test1;

import java.util.Random;

/**
 * Role
 *
 * @author 28189
 * @since 2024/11/30 17:22
 */
public class Role {
    private String name;
    private int blood;
    private char gender;
    String[] attacks = {
            "%s使用近身术，打向%s, ",
            "%s使用雷遁直击%s的腹部, ",
            "%s使用螺旋丸，蓄力攻击%s的小臂, ",
            "%s使用千鸟，攻击%s的头部, ",
            "%s使用幻影分身，攻击%s的背部, ",
            "%s使用瞬身移动，攻击%s的腰部, ",
            "%s使用天照，锁定了%s的大腿, ",
            "%s开启尾兽化，使用尾兽玉攻击%s, ",
            "%s召唤完全体须佐能乎挥剑斩向%s, ",
    };
    String[] injureds = {
            "%s闪身躲避了攻击",
            "%s使用格挡，化解了进攻",
            "%s使用防御结界，抵挡了攻击",
            "%s受击导致查克拉短缺",
            "%s被击中，体力渐渐下降",
            "%s使用尾兽化，躲避了攻击",
            "%s召唤完全体须佐能乎使自己处于免伤状态",
    };

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }
    //定义攻击
    public void attack(Role role) {
        //随机选择攻击方式
        Random r=new Random();
        int index=r.nextInt(attacks.length);
        String gong=attacks[index];
        System.out.printf(gong, this.getName(),role.getName());
        //计算伤害
        int hurt=r.nextInt(40)+1;
        int remainBlood=role.getBlood() - hurt;
        //判断剩余血量是否小于0
        remainBlood=remainBlood<0?0:remainBlood;
        role.setBlood(remainBlood);
        //受伤
        if(remainBlood>170){
            System.out.printf(injureds[0], role.getName());
        }
        else if(remainBlood>150&&remainBlood<=170){
            System.out.printf(injureds[1], role.getName());
        }
        else if(remainBlood>120&&remainBlood<=150){
            System.out.printf(injureds[2], role.getName());
        }
        else if(remainBlood>90&&remainBlood<=120){
            System.out.printf(injureds[3], role.getName());
        }
        else if(remainBlood>70&&remainBlood<=90){
            System.out.printf(injureds[4], role.getName());
        }
        else if(remainBlood>50&&remainBlood<=70){
            System.out.printf(injureds[5], role.getName());
        }
        else {
            System.out.printf(injureds[6], role.getName());
        }
        System .out.println();
        //扣除血量
        System.out.println(this.getName() + "攻击了" + role.getName()+"，造成了" + hurt + "点伤害," + role.getName() + "剩余血量：" + remainBlood);
    }
}
